﻿using RAP.Framework.Libary.DataSource.Context;
using RAP.Framework.Libary.DataSource.Model;
using RAP.Framework.Libary.ServerCacheManager;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using static RAP.Framework.Libary.DataSource.ServiceUtils;

namespace RAP.Framework.Libary.SqlDataService.Service
{
  /// <summary>
  ///  SQL数据访问服务接口
  /// </summary>
  public interface ISqlDataService
  {
    bool IsDebug { get; set; }
    ICacheManager Cache { get; set; }
    string NameSpace { get; set; }
    string CacheProxyKey { get; set; }

    event Action<SqlDataServiceEventArgs> OnBeginExecute;
    event Action<SqlDataServiceEventArgs> OnEndExecute;

    IQueryParams CreateQueryParams(IQueryParams param = null);
    IQueryParams CreateQueryParams(IDictionary param = null);

    IQueryResult ExecuteSync(
      IQueryParams param = null,
            string cacheKey = CacheTypes.None,
            [CallerMemberName] string templateName = null,
            string defaultDataSourceId = null,
            bool allowFireEvent = true,
      IDataServiceContext context = null);

    IQueryResult ExecuteSync(
      IDictionary param,
      string cacheKey = CacheTypes.None,
      [CallerMemberName] string templateName = null,
      string defaultDataSourceId = null,
      bool allowFireEvent = true,
      IDataServiceContext context = null);

    Task<IQueryResult> Execute(
      IQueryParams param = null,
            string cacheKey = CacheTypes.Auto,
            [CallerMemberName] string templateName = null,
            string defaultDataSourceId = null,
            bool allowFireEvent = true,
      IDataServiceContext context = null);

    Task<IQueryResult> Execute(
      IDictionary param,
      string cacheKey = CacheTypes.Auto,
      [CallerMemberName] string templateName = null,
      string defaultDataSourceId = null,
      bool allowFireEvent = true,
      IDataServiceContext context = null);

    Task<object> ExecuteNonQuery(
      IQueryParams param = null,
            [CallerMemberName] string templateName = null,
            string defaultDataSourceId = null,
            bool allowFireEvent = true,
      IDataServiceContext context = null);

    Task<object> ExecuteNonQuery(
      IDictionary param,
      [CallerMemberName] string templateName = null,
      string defaultDataSourceId = null,
      bool allowFireEvent = true,
      IDataServiceContext context = null);

    Task<IQueryResult> ExecuteNoCache(
      IQueryParams param = null,
            [CallerMemberName] string templateName = null,
            string defaultDataSourceId = null,
            bool allowFireEvent = true,
      IDataServiceContext context = null);

    Task<IQueryResult> ExecuteNoCache(
      IDictionary param,
      [CallerMemberName] string templateName = null,
      string defaultDataSourceId = null,
      bool allowFireEvent = true,
      IDataServiceContext context = null);
  }
}
